noselection: Make constructor transfer full
authorMatthias Clasen <mclasen@redhat.com>
Sun, 26 Jul 2020 20:55:43 +0000 (16:55 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 26 Jul 2020 22:04:40 +0000 (18:04 -0400)
This is for consistency with other wrapping list constructors.
We want them all to be transfer full, allow-none.

Update all callers.

demos/gtk-demo/listview_clocks.c
demos/gtk-demo/listview_colors.c
demos/gtk-demo/listview_settings.c
demos/gtk-demo/listview_weather.c
demos/gtk-demo/listview_words.c
gtk/gtknoselection.c
gtk/inspector/actions.c
gtk/inspector/list-data.c
gtk/inspector/prop-list.c

index 4578c229cd755b2289657d333a41bf88d90ed732..80dcb8505d4561b51e1f043ce07c0a553404a31e 100644 (file)
@@ -462,7 +462,6 @@ do_listview_clocks (GtkWidget *do_widget)
     {
       GtkWidget *gridview, *sw;
       GtkListItemFactory *factory;
-      GListModel *model;
       GtkNoSelection *selection;
 
       /* This is the normal window setup code every demo does */
@@ -489,12 +488,10 @@ do_listview_clocks (GtkWidget *do_widget)
       gtk_scrollable_set_hscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
       gtk_scrollable_set_vscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
 
-      model = create_clocks_model ();
-      selection = gtk_no_selection_new (model);
+      selection = gtk_no_selection_new (create_clocks_model ());
       gtk_grid_view_set_model (GTK_GRID_VIEW (gridview), G_LIST_MODEL (selection));
       gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), gridview);
       g_object_unref (selection);
-      g_object_unref (model);
     }
 
   if (!gtk_widget_get_visible (window))
index edbdb75c4dae104565a7950131c7d19547d3e7de..94210bf9ceaa6aa0f549135948cb196460275ab2 100644 (file)
@@ -970,7 +970,6 @@ do_listview_colors (GtkWidget *do_widget)
 
       no_selection = G_LIST_MODEL (gtk_no_selection_new (selection_filter));
       gtk_grid_view_set_model (GTK_GRID_VIEW (selection_view), no_selection);
-      g_object_unref (selection_filter);
       g_object_unref (no_selection);
 
       selection_info_toggle = gtk_toggle_button_new ();
index 49dca2376a519e6117905bcd1e9aad3b1ea53598..0ddd61889b082f948f62891f6049b52c8f04c2b4 100644 (file)
@@ -214,7 +214,6 @@ transform_settings_to_keys (GBinding     *binding,
   GtkSortListModel *sort_model;
   GtkFilterListModel *filter_model;
   GtkFilter *filter;
-  GtkNoSelection *selection_model;
   char **keys;
   guint i;
 
@@ -248,10 +247,7 @@ transform_settings_to_keys (GBinding     *binding,
   g_set_object (&current_filter, filter);
   filter_model = gtk_filter_list_model_new (G_LIST_MODEL (sort_model), filter);
 
-  selection_model = gtk_no_selection_new (G_LIST_MODEL (filter_model));
-  g_object_unref (filter_model);
-
-  g_value_take_object (to_value, selection_model);
+  g_value_take_object (to_value, gtk_no_selection_new (G_LIST_MODEL (filter_model)));
 
   return TRUE;
 }
index 535a9d179b71cfbb107956c1e6aa6a1eccbd846c..f17ff0892103279a31345474f7836a10685c55b8 100644 (file)
@@ -281,7 +281,7 @@ GtkWidget *
 create_weather_view (void)
 {
   GtkWidget *listview;
-  GListModel *model, *selection;
+  GListModel *selection;
   GtkListItemFactory *factory;
 
   factory = gtk_signal_list_item_factory_new ();
@@ -290,11 +290,9 @@ create_weather_view (void)
   listview = gtk_list_view_new_with_factory (factory);
   gtk_orientable_set_orientation (GTK_ORIENTABLE (listview), GTK_ORIENTATION_HORIZONTAL);
   gtk_list_view_set_show_separators (GTK_LIST_VIEW (listview), TRUE);
-  model = create_weather_model ();
-  selection = G_LIST_MODEL (gtk_no_selection_new (model));
+  selection = G_LIST_MODEL (gtk_no_selection_new (create_weather_model ()));
   gtk_list_view_set_model (GTK_LIST_VIEW (listview), selection);
   g_object_unref (selection);
-  g_object_unref (model);
 
   return listview;
 }
index 95664ed27961f33321676f4dd54e668848167c6d..4545ed48aa24a5bad95b703befd86d71c504af0c 100644 (file)
@@ -226,7 +226,6 @@ do_listview_words (GtkWidget *do_widget)
       g_signal_connect (filter_model, "notify::pending", G_CALLBACK (update_title_cb), progress);
       update_title_cb (filter_model);
 
-      g_object_unref (filter_model);
     }
 
   if (!gtk_widget_get_visible (window))
index 8027d003b2de6c266dcf45bf33b3d3b2d640b926..597eb4af3147faffbb7187f603939d6b5d5e1cb8 100644 (file)
@@ -216,7 +216,7 @@ gtk_no_selection_init (GtkNoSelection *self)
 
 /**
  * gtk_no_selection_new:
- * @model: (transfer none): the #GListModel to manage
+ * @model: (allow-none) (transfer full): the #GListModel to manage, or %NULL
  *
  * Creates a new selection to handle @model.
  *
@@ -225,11 +225,18 @@ gtk_no_selection_init (GtkNoSelection *self)
 GtkNoSelection *
 gtk_no_selection_new (GListModel *model)
 {
+  GtkNoSelection *self;
+
   g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
 
-  return g_object_new (GTK_TYPE_NO_SELECTION,
+  self = g_object_new (GTK_TYPE_NO_SELECTION,
                        "model", model,
                        NULL);
+
+  /* consume the reference */
+  g_clear_object (&model);
+
+  return self;
 }
 
 /**
@@ -253,8 +260,8 @@ gtk_no_selection_get_model (GtkNoSelection *self)
  * @self: a #GtkNoSelection
  * @model: (allow-none): A #GListModel to wrap
  *
- * Sets the model that @self should wrap. If @model is %NULL, this
- * model will be empty.
+ * Sets the model that @self should wrap.
+ * If @model is %NULL, this model will be empty.
  **/
 void
 gtk_no_selection_set_model (GtkNoSelection *self,
index 9f68ded33ebb53983777b2c1a1813ada097ac368..339645e5906485c2f4bdc7bcf567b0236c4bf7a4 100644 (file)
@@ -400,7 +400,6 @@ constructed (GObject *object)
                                                   g_object_ref (gtk_column_view_get_sorter (GTK_COLUMN_VIEW (sl->list)))));
   model = G_LIST_MODEL (gtk_no_selection_new (sorted));
   gtk_column_view_set_model (GTK_COLUMN_VIEW (sl->list), model);
-  g_object_unref (sorted);
   g_object_unref (model);
 }
 
index 596a4dbbddfa2776af78c582e97a587b5d761806..fe1006edcbea53335ab2f076a8851c8762ee73c9 100644 (file)
@@ -85,7 +85,7 @@ gtk_inspector_list_data_set_object (GtkInspectorListData *sl,
   g_object_set (page, "visible", TRUE, NULL);
 
   sl->object = G_LIST_MODEL (object);
-  selection = gtk_no_selection_new (sl->object);
+  selection = gtk_no_selection_new (g_object_ref (sl->object));
   gtk_column_view_set_model (sl->view, G_LIST_MODEL (selection));
   g_object_unref (selection);
 }
index e7d2aeb21b3db21f85bd0b983ea1ab220465630c..970e83cb4a6d52e205f876bf048e1d310546c923 100644 (file)
@@ -633,7 +633,6 @@ gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl,
   gtk_widget_show (GTK_WIDGET (pl));
 
   g_object_unref (list);
-  g_object_unref (sorted);
 
   return TRUE;
 }